package cn.itcast.order.service;

import cn.itcast.feign.client.UserClient;
import cn.itcast.feign.pojo.User;
import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;

//    @Autowired
//    private RestTemplate restTemplate;
    @Autowired
    private UserClient userClient;

    // 让sentinel能够监控到 资源
    @SentinelResource("goods")
    public void queryGoods(){
        System.out.println("查询商品");
    }


    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
        // 2. 远程调用用户微服务
        User user = userClient.queryById(order.getUserId());
        // 3. 将得到的用户信息 设置到order中
        order.setUser(user);
        // 4.返回
        return order;
    }
}
